﻿namespace LogManager.Gui.Converters
{
    using LogManager.Core.Models;
    using System;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Media;

    public class LocationPathsConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(values[0] is ILocation))
            { return null; }

            var location = (ILocation)values[0];
            FlowDocument doc = null;

            if (parameter.ToString() == "Path")
            {
                Run block_prefix = new Run("\\\\" + location.ParentServer.Ip + "\\");
                block_prefix.Foreground = Brushes.Black;
                block_prefix.FontWeight = FontWeights.Bold;

                //suffixe
                Run block_dossierDest = new Run(location.Path);

                Paragraph papra = new Paragraph();
                papra.Inlines.Add(block_prefix);
                papra.Inlines.Add(block_dossierDest);
                doc = new FlowDocument(papra);
            }
            else if (parameter.ToString() == "Name")
            {
                var prefix = "\\\\" + location.ParentServer.ParentPlateform.ParentWarehouse.Ip +
                    "\\" + location.ParentServer.ParentPlateform.Depository +
                    "\\" + location.ParentServer.ParentPlateform.Name +
                    "\\" + location.ParentServer.Name + "\\";

                Run block_prefix = new Run(prefix);
                block_prefix.Foreground = System.Windows.Media.Brushes.Black;
                block_prefix.FontWeight = FontWeights.Bold;

                //suffixe
                Run block_dossierDest = new Run(location.Name);

                Paragraph papra = new Paragraph();
                papra.Inlines.Add(block_prefix);
                papra.Inlines.Add(block_dossierDest);
                doc = new FlowDocument(papra);
            }

            return doc;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
